import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'


Vue.use(Router)

const routes = [
    {
        path: '/demo',
        component: resolve => require(['@/views/demo.vue'], resolve),
    },
    {
        path: '/test',
        component: resolve => require(['@/views/test.vue'], resolve),
    },
    {
        path: '/',
        component: resolve => require(['@/views/login.vue'], resolve)
    },

];


// 创建路由器
const router = new Router({
    routes
});

router.beforeEach((to, from, next) => {
    next();
    store.dispatch('editableTabs/worktabRoute', {
        to: {
            name: to.name ? to.name : '',
            tabname: (to.meta && to.meta.tabname) ? to.meta.tabname : '',
            path: to.path
        },
        from: {
            name: from.name ? from.name : '',
            tabname: (from.meta && from.meta.tabname) ? from.meta.tabname : '',
            path: from.path
        }
    });
});

export default router
